<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="平方" onclick="f()">
<div>
    结果:<span id="i2"></span>
</div>
<script>
    function f() {
        //得到文本框和span对象
        let i = document.querySelector("#i1");
        let i2 = document.querySelector("#i2");

        if (isNaN(i.value)){
            i2.innerText="输入错误!"
            return;
        }

        //把文本框的值取出赋值给span
        // i2.innerText = (i.value * i.value);
        /*加法*/
        // i2.innerText = parseFloat(i.value) * parseFloat(i.value);
        i2.innerText = (i.value*1 + i.value*1);
    }

</script>
</body>
</html>